Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only apply MCMT plugin on MCMTGate #13596

Merged
merged 5 commits into from
Jan 7, 2025

Conversation

Cryoris
Copy link
Contributor

@Cryoris Cryoris commented Dec 23, 2024

Summary

Fixes #13563, by enabling the high-level synthesis plugins of MCMT only for the MCMTGate, not any gate called "mcmt".

Details and comments

While we often let it be the user's responsibility to be mindful with gate names, this is a special case as we provide a circuit called "mcmt". This can cause innocent-looking code to break, so we should add this check at least until the MCMT circuit is removed 🙂

@Cryoris Cryoris added Changelog: Bugfix Include in the "Fixed" section of the changelog mod: circuit Related to the core of the `QuantumCircuit` class or the circuit library labels Dec 23, 2024
@Cryoris Cryoris added this to the 1.3.2 milestone Dec 23, 2024
@qiskit-bot
Copy link
Collaborator

One or more of the following people are relevant to this code:

  • @Cryoris
  • @Qiskit/terra-core
  • @ajavadia

@coveralls
Copy link

coveralls commented Dec 23, 2024

Pull Request Test Coverage Report for Build 12649042437

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 12 of 31 (38.71%) changed or added relevant lines in 1 file are covered.
  • 24 unchanged lines in 4 files lost coverage.
  • Overall coverage increased (+0.004%) to 88.938%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/transpiler/passes/synthesis/hls_plugins.py 12 31 38.71%
Files with Coverage Reduction New Missed Lines %
qiskit/transpiler/passes/synthesis/hls_plugins.py 1 83.38%
crates/accelerate/src/two_qubit_decompose.rs 1 92.13%
crates/qasm2/src/lex.rs 2 92.23%
qiskit/quantum_info/operators/symplectic/sparse_pauli_op.py 20 94.58%
Totals Coverage Status
Change from base Build 12535289542: 0.004%
Covered Lines: 79443
Relevant Lines: 89324

💛 - Coveralls

alexanderivrii
alexanderivrii previously approved these changes Dec 26, 2024
Copy link
Contributor

@alexanderivrii alexanderivrii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix looks straightforward, LGTM!

I had one tiny off-topic question.

Comment on lines +295 to +296
mcmt = MCMT(gate=gate, num_ctrl_qubits=1, num_target_qubits=1)
circuit.append(mcmt, circuit.qubits) # append the MCMT circuit as gate called "MCMT"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit off-topic. Here we are appending the quantum circuit mcmt to the quantum circuit circuit, yet the docstring for append states instruction: Operation | CircuitInstruction. The code does work, since a QuantumCircuit defines a to_instruction method, which append tries to use when the instruction is not of type Operation. Would it be slightly cleaner to change to circuit.append(mcmt.to_instruction(), ...), or should we change the typehint for the append method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating the docs for append sounds good, since we use append(QuantumCircuit) all over the place 🤔

Copy link
Contributor

@alexanderivrii alexanderivrii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Cryoris for also updating our included plugins so that they all follow the same convention. And you have taken the art of writing tests to a completely new level -- now they read like a fiction story (unfortunate names, intruder circuits, etc) 😄.

@alexanderivrii alexanderivrii added this pull request to the merge queue Jan 7, 2025
Merged via the queue into Qiskit:main with commit 0eeba0d Jan 7, 2025
17 checks passed
@Cryoris Cryoris deleted the fix-mcmt-transpile branch January 7, 2025 12:13
@Cryoris
Copy link
Contributor Author

Cryoris commented Jan 7, 2025

Haha I'm hoping to provide some joy for people reviewing the code 😛

@Cryoris
Copy link
Contributor Author

Cryoris commented Jan 7, 2025

@Mergifyio backport stable/1.3

Copy link
Contributor

mergify bot commented Jan 7, 2025

backport stable/1.3

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Jan 7, 2025
* Only apply MCMT plugin on MCMTGate

* add checks for other gates

* fix reno

* use == instead of equiv

(cherry picked from commit 0eeba0d)
github-merge-queue bot pushed a commit that referenced this pull request Jan 7, 2025
* Only apply MCMT plugin on MCMTGate

* add checks for other gates

* fix reno

* use == instead of equiv

(cherry picked from commit 0eeba0d)

Co-authored-by: Julien Gacon <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog mod: circuit Related to the core of the `QuantumCircuit` class or the circuit library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error transpiling circuit containing MCMT gate
5 participants